/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Modificar_Item.java
 *
 * Created on 28-feb-2011, 20:53:27
 */
package puntoventa;

import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author gadiaz3
 */
public class Modificar_Item extends javax.swing.JFrame {

    /** Creates new form Modificar_Item */
    public Modificar_Item() {
        initComponents();
        this.setLocationRelativeTo(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        FPrecio = new javax.swing.JTextField();
        FNom = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        FID = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        VolverB = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        MProductoB = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        FStock = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        FProv = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel3.setText("Nombre del Producto:");

        jLabel2.setText("ID:");

        jLabel5.setText("Precio:");

        VolverB.setText("Volver");
        VolverB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VolverBActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        jLabel1.setText("Modificar Producto");

        MProductoB.setText("Modificar Producto...");
        MProductoB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MProductoBActionPerformed(evt);
            }
        });

        jLabel6.setText("Proveedor:");

        jLabel4.setText("Cantidad de Stock:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(34, 34, 34)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel4)
                            .add(jLabel6)
                            .add(jLabel5)
                            .add(VolverB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(MProductoB, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .add(FID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, FNom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .add(FProv, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .add(FStock, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .add(FPrecio, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(199, Short.MAX_VALUE)
                        .add(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(FNom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FStock, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .add(8, 8, 8)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FProv, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FPrecio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(MProductoB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(VolverB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MProductoBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MProductoBActionPerformed
        String ID = FID.getText();
        String Nombre = FNom.getText();
        String Stock = FStock.getText();
        String Prov = FProv.getText();
        String Precio = FPrecio.getText();


        //Conexión a la BD

        //Condiciones
        if (FID.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el [ID] para modificar.", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else if (FNom.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el Nombre para modificar clave [" + ID + "]", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else if (FStock.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el Stock o dejarlo igual para modificar clave [" + ID + "]", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else if (FProv.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el Proveedor o dejarlo igual para modificar clave [" + ID + "]", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else if (FPrecio.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(null, "Debe especificar el Precio o dejarlo igual para modificar clave [" + ID + "]", "Atencion", JOptionPane.INFORMATION_MESSAGE);
        } else
            try {

                Connection c = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/PDV", "root", "root");
                Statement sql = (Statement) c.createStatement();

                sql.executeUpdate("update Productos set Nombre='" + Nombre + "', Stock=" + Stock + ", Proveedor='" + Prov + "', Precio=" + Precio + " where ID=" + ID + "");
                JOptionPane.showMessageDialog(null, "Producto [" + ID + "] Modificado!", "Atencion", JOptionPane.INFORMATION_MESSAGE);



                FID.setText("");
                FNom.setText("");
                FStock.setText("");
                FProv.setText("");
                FPrecio.setText("");

            } catch (SQLException ex) {

                ex.printStackTrace();
            }

}//GEN-LAST:event_MProductoBActionPerformed

    private void VolverBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VolverBActionPerformed
        Administrador Admin = new Administrador();
        Admin.setVisible(true);
        this.dispose();

    }//GEN-LAST:event_VolverBActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Modificar_Item().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField FID;
    private javax.swing.JTextField FNom;
    private javax.swing.JTextField FPrecio;
    private javax.swing.JTextField FProv;
    private javax.swing.JTextField FStock;
    private javax.swing.JButton MProductoB;
    private javax.swing.JButton VolverB;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables
}
